package _26define;

import java.util.Random;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.TimeUnit;

public class Demo3 {
    public static void main(String[] args) {
        ExecutorService pool= Executors.newCachedThreadPool();
        Random random=new Random();
        for (int i = 0; i < 10; i++) {
            pool.submit(new Task(random.nextInt(11)));
        }
        pool.shutdown();
    }
}
class Task implements Runnable{
    int sleepTime;

    public Task(int sleepTime) {
        this.sleepTime = sleepTime;
    }

    @Override
    public void run() {
        try {
            TimeUnit.SECONDS.sleep(sleepTime);
            System.out.println(Thread.currentThread().getName()+"休眠了"+sleepTime+"s");
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
    }
}
